<%@ page language="java"  contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" isELIgnored="false"%>
<%@page errorPage="Error.jsp" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<%@ taglib prefix="f" uri="http://java.sun.com/jstl/fmt_rt" %>    
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="renderer" content="webkit">
<title></title>
<link rel="stylesheet" href="${pageContext.request.contextPath}/css/pintuer.css">
<link rel="stylesheet" href="${pageContext.request.contextPath}/css/admin.css">
<link rel="stylesheet" href="${pageContext.request.contextPath}/css/toastr.css">
<script src="${pageContext.request.contextPath}/js/jquery.js"></script>
<script src="${pageContext.request.contextPath}/js/pintuer.js"></script>
<script src="${pageContext.request.contextPath}/js/toastr.min.js"></script>
</head>
<body>
<script type="text/javascript">
    function addCaptor(){
    	var captor = $("#addCaptorName").val();
    	if(captor==""){
    		alert("分类名称不能为空");
    	}
    	else{
    		 $.ajax({
    	    	  type:"POST",
    	    	  url:"${pageContext.request.contextPath}/addCaptor",
    	    	  data:{"captor":captor},
    	    	  success:function(data){
    	    		  if(data.result=="操作成功"){
    	    			  alert("添加成功");
    	    			  window.location.href = "${pageContext.request.contextPath}/enterBookTypeManage"
    	    		  }
    	    		  else if(data.result=="存在"){
    	    			  alert("该类别以及存在，无需添加");
    	    		  }
    	    		  else{
    	    			  alert("添加失败");
    	    		  }
    	    	  }
    	      });
    	}
    	return false;
    }
    	
    function deleteCaptor(){
    	var captor = $("#deleteCaptorName").val();
    	if(captor==""){
    		alert("分类名称不能为空");
    	}
    	else{
    		 $.ajax({
    	    	  type:"POST",
    	    	  url:"${pageContext.request.contextPath}/deleteCaptor",
    	    	  data:{"captor":captor},
    	    	  success:function(data){
    	    		  if(data.result=="操作成功"){
    	    			  alert("删除成功");
    	    			  window.location.href = "${pageContext.request.contextPath}/enterBookTypeManage"
    	    		  }
    	    		  else if(data.result=="操作失败"){
    	    			  alert("该类别不存在");
    	    		  }
    	    		  else{
    	    			  alert("删除失败");
    	    		  }
    	    	  }
    	      });
    	}
    	return false;
    }
 
    function checkBookId(){
 	   var id = $(".bookId").val();
 	    $.ajax({
 		   data:{"bookId":id},
 		   type:"POST",
 		   url:"${pageContext.request.contextPath}/checkBookId",
 		   success:function(data){
 			   if(data.result=="工号已经存在"){
 				   $("#username").css('color','red');
 				   $("#username").css('display','inline');
 				   $("#username").text("该书号已经存在");
 				   $(".bookId").val("");
 			   }
 			   else{
 				   $("#username").text("该书号可以使用");
 				   $("#username").css('color','green');
 				   $("#username").css('display','inline');
 			   }
 		   }
 	   }) 
    }
    
</script>
<div class="panel admin-panel">
  <div class="panel-head"><strong><span class="icon-key"></span> 书籍分类管理</strong></div>
  <div class="body-content">
    <form method="post" class="form-x" action="">
      <div class="form-group">
        <div class="label">
          <label for="sitename">所有书籍分类:</label>
        </div>
        <div class="field">
          <label style="line-height:33px;">
               <c:forEach items="${list}" var="msg">
                  <c:out value="${msg}"></c:out>&nbsp;&nbsp;
              </c:forEach> 
          </label>
        </div>
      </div>      
      <div class="form-group">
        <div class="label">
          <label for="sitename">添加分类：</label>
        </div>
        <div class="field">
          <input type="username" id="addCaptorName" class="input w50" id="mpass" name="mpass" size="50" placeholder="请输入分类名称"  />       
        </div>
      </div>     
      
       <div class="form-group">
        <div class="label">
          <label></label>
        </div>
        <div class="field">
           <a style="margin-left: 15px;" class="button border-green" href="#"
									onclick="addCaptor()"><span
									class="icon-trash-o"></span> 提交</a>   
        </div>
      </div>     
     
     <div class="form-group">
        <div class="label">
          <label for="sitename">删除分类：</label>
        </div>
        <div class="field">
          <input type="username" id="deleteCaptorName" class="input w50" id="mpass" name="mpass" size="50" placeholder="请输入分类名称"  />       
        </div>
      </div>   
     
      <div class="form-group">
        <div class="label">
          <label></label>
        </div>
        <div class="field">
          <a style="margin-left: 15px;" class="button border-green" href="#"
									onclick="deleteCaptor()"><span
									class="icon-trash-o"></span> 提交</a>  
        </div>
      </div>    
        
    </form>
  </div>
  
  <div class="panel-head"><strong><span class="icon-key"></span> 书籍添加</strong></div>
  <div class="body-content">
    <form method="post" class="form-x" action="${pageContext.request.contextPath}/addBook">
          
      <div class="form-group">
        <div class="label">
          <label for="sitename">选择类别：</label>
        </div>
        <div class="field">
          <select name="bookType"
						class="input week" onchange="changesearch()"
						style="width: 90px; line-height: 17px; display: inline-block">
					     <c:forEach items="${list}" var="msg">
					         <option value="${msg}">${msg}</option>
					     </c:forEach>
		 </select>    
        </div>
      </div>      
      
        <div class="form-group">
        <div class="label">
          <label>书号：</label>
        </div>
        <div class="field">
          <input type="text" id="title"  name="bookId" class="input w50 bookId" value="" onchange="checkBookId()"  data-validate="required:请输入书号" />
          <div class="tips"></div><span style="margin-left: 10px;display:none; position: relative;top:10px;" id="username">该书号已存在</span>
        </div>
      </div>
      
        <div class="form-group">
        <div class="label">
          <label>书名：</label>
        </div>
        <div class="field">
          <input type="text" id="title" name="bookName" class="input w50 name" value=""   />
          <div class="tips"></div>
        </div>
        </div>
        
         
        <div class="form-group">
        <div class="label">
          <label>书本总数：</label>
        </div>
        <div class="field">
          <input type="text" id="title" name="bookCount" class="input w50 name" value=""   />
          <div class="tips"></div>
        </div>
        </div>
        
          <div class="form-group">
        <div class="label">
          <label>作者：</label>
        </div>
        <div class="field">
          <input type="text" id="title" name="author" class="input w50 name" value=""   />
          <div class="tips"></div>
        </div>
        </div>
       <div class="form-group">
        <div class="label">
          <label>书籍简介：</label>
        </div>
        <div class="field">
          <textarea class="input" id="content" name="introduce" style=" height:150px;"></textarea>
          <div class="tips"></div>
        </div>
      </div>
     
      <div class="form-group">
        <div class="label">
          <label></label>
        </div>
        <div class="field">
          <button class="button bg-main icon-check-square-o" type="submit" id="submitButton">提交</button>   
        </div>
      </div>    
        
    </form>
  </div>
</div>
</body></html>